/**
 * 
 */
package com.m7012e.a_remote.ar_listeners.network.protocol;

import java.io.IOException;

import com.leoj.utils.tcp_network.ApplicationProtocol;
import com.leoj.utils.tcp_network.TcpConnection;
import com.m7012e.a_remote.ar_listeners.exception.WrongMessageProtocolException;
import com.m7012e.a_remote.communication.tcpMessages.DisplayRequestMessage;
import com.m7012e.a_remote.communication.tcpMessages.NotAvailableMessage;

/**
 * @author leoj
 *
 */
public class DaemonBusyProtocol implements ApplicationProtocol{

	/* (non-Javadoc)
	 * @see com.leoj.utils.tcp_network.ApplicationProtocol#handleClient(com.leoj.utils.tcp_network.TcpConnection)
	 */
	@Override
	public void handleClient(TcpConnection client) {
		try {
			Object o = client.read();
			if(! (o instanceof DisplayRequestMessage)){
				throw new WrongMessageProtocolException();
			}
			client.send(new NotAvailableMessage());
			client.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
